package com.ruoyi.project.wodemand.controller;

import java.util.List;

import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.security.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wodemand.domain.TSheetconditions;
import com.ruoyi.project.wodemand.service.ITSheetconditionsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 配置工单条件Controller
 *
 * @author lt
 * @date 2020-04-21
 */
@RestController
@RequestMapping("/wodemand/SHEETCONDITIONS")
public class TSheetconditionsController extends BaseController
{
    @Autowired
    private ITSheetconditionsService tSheetconditionsService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询配置工单条件列表
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETCONDITIONS:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSheetconditions tSheetconditions)
    {
        startPage();
        List<TSheetconditions> list = tSheetconditionsService.selectTSheetconditionsList(tSheetconditions);
        return getDataTable(list);
    }

    /**
     * 导出配置工单条件列表
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETCONDITIONS:export')")
    @Log(title = "配置工单条件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSheetconditions tSheetconditions)
    {
        List<TSheetconditions> list = tSheetconditionsService.selectTSheetconditionsList(tSheetconditions);
        ExcelUtil<TSheetconditions> util = new ExcelUtil<TSheetconditions>(TSheetconditions.class);
        return util.exportExcel(list, "SHEETCONDITIONS");
    }

    /**
     * 获取配置工单条件详细信息
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETCONDITIONS:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tSheetconditionsService.selectTSheetconditionsById(id));
    }

    /**
     * 新增配置工单条件
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETCONDITIONS:add')")
    @Log(title = "配置工单条件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSheetconditions tSheetconditions)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        tSheetconditions.setReserved2(operName);
        return toAjax(tSheetconditionsService.insertTSheetconditions(tSheetconditions));
    }

    /**
     * 修改配置工单条件
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETCONDITIONS:edit')")
    @Log(title = "配置工单条件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSheetconditions tSheetconditions)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        tSheetconditions.setReserved3(operName);
        return toAjax(tSheetconditionsService.updateTSheetconditions(tSheetconditions));
    }

    /**
     * 删除配置工单条件
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETCONDITIONS:remove')")
    @Log(title = "配置工单条件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSheetconditionsService.deleteTSheetconditionsByIds(ids));
    }
}
